 <template>
  <div>
    <el-container class="layout-page">
      <el-aside width="210px">
        <div class="logo">
          <h5 class="logo"><img src="@/assets/logo2.png" alt="" /></h5>
        </div>
        <el-menu
          router
          :default-active="$route.path"
          background-color="#313a46"
          text-color="#8391a2"
          active-text-color="#FFF"
        >
          <el-menu-item index="/student">
            <i class="el-icon-notebook-1"></i>
            <span>学员管理</span>
            <ul></ul>
          </el-menu-item>
        </el-menu>
      </el-aside>
      <el-container>
        <el-header>
          <el-button @click="init" type="primary">点我初始化按钮</el-button>
          <div class="user"></div>
          <div class="logout">
            <el-popconfirm title="您确认退出吗？" @confirm="logout">
              <i
                slot="reference"
                title="logout"
                class="el-icon-switch-button"
              ></i>
            </el-popconfirm>
          </div>
        </el-header>
        <el-main>
          <router-view />
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import { delToken } from '@/api/storage'
import { initAPI } from '@/api/user'
import { mapMutations, mapState } from 'vuex'
export default {
  name: 'LayoutIndex',
  data () {
    return {}
  },

  methods: {
    ...mapMutations('user', ['saveToken']),
    ...mapState('user', ['list']),
    logout () {
      this.$router.push('/login')
      delToken()
      this.saveToken('')
    },

    async init () {
      const res = await initAPI()
      if (res.data.code === 0) {
        this.$message.success(res.data.message)
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.layout-page {
  height: 100vh;

  .el-main {
    padding: 0;
  }
  .el-aside {
    background: #313a46;
    .logo {
      color: #fff;
      font-size: 20px;
      height: 60px;
      line-height: 60px;
      text-align: center;
    }
    .el-menu {
      border-right: none;
      margin-top: 20px;
      &-item {
        background-color: transparent !important;
        > span,
        i {
          padding-left: 5px;
        }
      }
    }
  }
  .el-header {
    box-shadow: 0px 0px 35px 0px rgba(154, 161, 171, 0.15);
    background: #fff;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    z-index: 999;
    .user {
      display: flex;
      align-items: center;
      background: #fafbfd;
      height: 60px;
      border: 1px solid #f1f3fa;
      padding: 0 15px;
      .el-avatar {
        margin-right: 15px;
      }
    }
    .logout {
      font-size: 20px;
      color: #999;
      cursor: pointer;
      padding: 0 15px;
    }
  }
  .el-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #aaa;
    border-top: 1px solid rgba(152, 166, 173, 0.2);
    font-size: 14px;
  }
}
</style>
